<%@page import="javax.portlet.PortletURL"%>
<%@page import="com.springlibrary.slayer.model.LMSBook"%>
<%@page import="java.util.List"%>
<%@page import="com.springlibrary.slayer.service.LMSBookLocalServiceUtil"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet" %>

<portlet:defineObjects/>

<h1>List of Books</h1>
 
 <%
	int count = LMSBookLocalServiceUtil.getLMSBooksCount();
	List<LMSBook> books = LMSBookLocalServiceUtil.getLMSBooks(0, count);
	
	PortletURL editURL=renderResponse.createRenderURL();
	editURL.setParameter("action", "updateForm");
	
	PortletURL deleteURL = renderResponse.createActionURL();
	deleteURL.setParameter("action", "deleteBook");

%>
 <table border="1" width="80%">
 <tr>
		<th>Book Title</th>
		<th>Author</th>
		<th>Create Date</th>
		<td>Edit</td>
		<td>Delete</td>
	</tr>
 <%
 for (LMSBook book : books) {
 %>
	<tr>
		<td><%= book.getBookTitle() %></td>
		<td><%= book.getAuthor() %></td>
		<td><%= book.getCreateDate() %></td>
		<td>
		<% 
			editURL.setParameter("bookId",String.valueOf(book.getBookId()));
		%>
			<a href="<%=editURL%>">Edit</a>
		</td>
		<td>
		<% 
			deleteURL.setParameter("bookId",String.valueOf(book.getBookId()));
		%>
			<a href="<%=deleteURL%>">Delete</a>
		</td>
	</tr>
	<%
 }
	%>
</table>